package ui.robots_wicket;

import org.apache.wicket.Page;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;

import unq.uis.robots.applicationsModels.JugadorVista;
import unq.uis.robots.applicationsModels.RobotVista;
import unq.uis.robots.model.Robot;

@SuppressWarnings("serial")
public class RepararPage extends WebPage{
	
	private RobotVista robotVista;
	private Page paginaAnterior;
	private JugadorVista jugadorVista;
//	private Component labelCosto;
	private FeedbackPanel feedbackPanel ;

	public RepararPage(Page page, Robot robot) {
		this.paginaAnterior = page;
		this.jugadorVista = (JugadorVista)this.paginaAnterior.getDefaultModelObject();
		Form<?> form = new FormCopado("repararForm", this.createModel(robot));
		form.setOutputMarkupId(true);
		this.agregarLabels(form);
		this.agregarTextField(form);
		this.agregarBotones(form);
		feedbackPanel = new FeedbackPanel("feedbackPanel");
		feedbackPanel.setOutputMarkupId(true);
		form.add(feedbackPanel);
		this.add(form);
		
	}
	
	protected CompoundPropertyModel<RobotVista> createModel(Robot robot) {
		this.robotVista = new RobotVista(robot);
		return new CompoundPropertyModel<RobotVista>(this.robotVista);
	}
	
	public void agregarLabels(Form<?> form){
		form.add(new Label("nombreRobot"));
		form.add(new Label("danio"));
		form.add( new Label("calcularCosto").setOutputMarkupId(true));
		this.add(new Label("nombreJugador", new PropertyModel<String>(this.jugadorVista, "nombre")));
		this.add(new Label("dineroJugador", new PropertyModel<Integer>(this.jugadorVista, "dinero")));
	}
	
	public void agregarTextField(Form<?> form){
		form.add(new TextField<String>("danioAReparar"));
	}
	
	public void agregarBotones(Form<?> form){
		
		form.add(new Button("costo") {
			@Override
			public void onSubmit() {

			
			}

		});
		
		
		form.add(new Button("aceptar") {
			@Override
			public void onSubmit() {
				RepararPage.this.robotVista.repararRobot();
				this.setResponsePage(paginaAnterior);
			}
		});
		
		Button cancelButton = new Button("cancelar"){
			@Override
			public void onSubmit() {
				this.setResponsePage(paginaAnterior);
			}
		};
		cancelButton.setDefaultFormProcessing(false);
		form.add(cancelButton);
	}	

}
